<?php

namespace app\admin\controller;

use app\common\model\ProductStock;
use app\common\model\ProductsType;
use think\Db;
use think\facade\Request;

class Trial extends Base
{
    public function __construct()
    {
        parent::__construct();
        $this->isLogin();
    }


    /**
     * 获取需要审核的商品管理
     * @route('trial/trialproductlist')
     */
    public function TrialProductList()
    {

        $ProductModel = new \app\common\model\Products();

        $get['class_id'] = input('get.class_id');
        $cond['approved'] = 1;
        $cond['class_id'] = $get['class_id'];

        $rs_data = $ProductModel->get_list_page($cond,'p.product_id desc p.approved asc','p.*,s.shop_name,t.type_name',$this->limit);

//        echo "<pre>";
//        var_dump($rs_data);
//        die;

        $tvar = array(
            "title" => "商品审核列表",
            "time"  => time(),
            "data"  => $rs_data,
            "get"  => $get,
            "classlist" => $ProductModel::$classlist,
        );
        $page = $rs_data->render();
        $this->assign("data", $tvar);
        $this->assign('page', $page);
        return $this->fetch('trial/product/trialproductlist');
    }


    /**
     * 审核商品通过
     * @route('trial/adoptproducts')
     */
    public function AdoptProducts()
    {
        $ProductModel = new \app\common\model\Products();

        if(Request::isAjax()){
            // 商品ID
            $ids = input('ids');
            // 更改审核状态
            $rs = $ProductModel->ProductsAdopt($ids);
            if($rs === false){
                $this->error('操作失败');
            }
            $this->success('操作成功');
        }
    }


    /**
     * @route('trial/productinfo')
     * 商品信息详情
     */
    public function ProductInfo()
    {
        $ProductModel = new \app\common\model\Products();

        $product_id = input('product_id');
        $describe = $ProductModel->getOne(['product_id' => $product_id],'describe');

        $tvar = array(
            "title" => "商品详情",
            "time"  => time(),
            "data"  => $describe,
        );

        $this->assign("data", $tvar);
        return $this->fetch('trial/product/productinfo');
    }


    /**
     * 商品不通过
     * @route('trial/failproduct')
     */
    public function FailProduct()
    {
        $ProductModel = new \app\common\model\Products();

        $product_id = input('product_id');

        if(Request::isPost()){
            $product_id = input('product_id');
            $param['reasons'] = input('reasons');
            $param['approved'] = 3;

            $rs = $ProductModel->edit($param, $product_id);
            if($rs === false){
                $this->error('操作失败');
            }
            $this->success('操作成功','/trial/trialproductlist');
        }

        $tvar = array(
            "title" => "商品审核",
            "time"  => time(),
            "product_id" => $product_id
        );

        $this->assign("data", $tvar);
        return $this->fetch('trial/product/failproduct');
    }









}